package apps.softtech.fastmarket.model;

import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;

public class Tag {
	public int getTagId() {
		return tagId;
	}

	public void setTagId(int tagId) {
		this.tagId = tagId;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public String getTagDescription() {
		return tagDescription;
	}

	public void setTagDescription(String tagDescription) {
		this.tagDescription = tagDescription;
	}

	
	
	public static final String TABLE_NAME = "Tag";

	public static final String TAG_ID = "st_TagId";
	private int tagId;

	public static final String TAG_NAME = "st_TagName";
	private String tagName;

	public static final String TAG_DESCRIPTION = "st_TagDescription";
	private String tagDescription;
	
	public static final String VALUE_TYPE = "st_valueType";
	private int valueType;

	public static final String TAG_VALUE_TYPE = "st_ValueType";
	private int tagValueType;

	public Tag() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Tag(int tagId, String tagName, String tagDescription) {
		super();
		this.tagId = tagId;
		this.tagName = tagName;
		this.tagDescription = tagDescription;
	}

	public Tag(String tagName, String tagDescription) {
		super();
		this.tagName = tagName;
		this.tagDescription = tagDescription;
	}

	/**
	 * get value of Tag
	 * 
	 * @author MUI
	 * @return ContentValues
	 */
	public ContentValues getValueTag() {
		ContentValues values = new ContentValues();
		values.put(TAG_NAME, this.getTagName());
		values.put(TAG_DESCRIPTION, this.getTagDescription());
		return values;
	}

	public void setValueFromCursor(Cursor c) {
		if (c.getColumnIndex(TAG_ID) >= 0) {
			setTagId(c.getInt(c.getColumnIndex(TAG_ID)));
		}
		if (c.getColumnIndex(TAG_NAME) >= 0) {
			setTagName(c.getString(c.getColumnIndex(TAG_NAME)));
		}
		if (c.getColumnIndex(TAG_DESCRIPTION) >= 0) {
			setTagDescription(c.getString(c.getColumnIndex(TAG_DESCRIPTION)));
		}
	}

	public int getTagValueType() {
		return tagValueType;
	}

	public void setTagValueType(int tagValueType) {
		this.tagValueType = tagValueType;
	}

	public void setTagFromJSON(JSONObject jsonObject) {
		try {
			try{
				this.tagId = Integer.valueOf(jsonObject.getString(TAG_ID));
			}catch(Exception e){
				return;
			}
			
			try {
				this.tagName = jsonObject.getString(TAG_NAME);
			} catch (Exception e) {
				return;
			}

			try {
				this.tagDescription = jsonObject.getString(TAG_DESCRIPTION);
			} catch (Exception e) {
				this.tagDescription = "";
			}

			try {
				this.tagValueType = jsonObject.getInt(TAG_VALUE_TYPE);
			} catch (Exception e) {
				this.tagValueType = 0;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
